Skip to content

codegen: improve "could not find field" error message - #233

Closed
fnune wants to merge 2 commits into
graphql-rust:masterfrom
fnune:improve-error-messages
Closed

codegen: improve "could not find field" error message#233
fnune wants to merge 2 commits into
graphql-rust:masterfrom
fnune:improve-error-messages

Conversation

@fnune

@fnune fnune commented Mar 31, 2019

Copy link
Copy Markdown

#97

I've considered adding newlines in between but I don't know if there's any existing convention that would conflict with that.

@fnune

fnune commented Mar 31, 2019

Copy link
Copy Markdown
Author
query RepoView($owner: String!, $name: String!) {
  bananas
  repository(owner: $owner, name: $name) {

// Etc
error: proc-macro derive panicked
  --> src/main.rs:23:10
   |
23 | #[derive(GraphQLQuery)]
   |          ^^^^^^^^^^^^
   |
   = help: message: Code generation failed.
           Could not find field `bananas`. Available fields: `__typename, codeOfConduct, codesOfConduct, license, licenses, marketplaceCategories, marketplaceCategory, marketplaceListing, marketplaceListings, meta, node, nodes, organization, rateLimit, relay, repository, repositoryOwner, resource, search, topic, user, viewer`.    

Comment thread graphql_client_codegen/src/shared.rs Outdated
.map(|ref field| &field.name)
.fold(String::new(), |mut acc, item| {
acc.push_str(item);
acc.push_str(", ");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Itertools::format would just be better.

fields.iter().map(|ref field| &field.name).format("`, `")

This keeps the field names enclosed in "`", but leaves the commas without markup.

@fnune

fnune commented Apr 2, 2019

Copy link
Copy Markdown
Author

That does look better. Added as an additional commit so it can be reviewed separately.

Comment thread graphql_client_codegen/src/shared.rs Outdated
format_err!(
"Could not find field `{}`. Available fields: `{}`.",
name,
format_available_fields(fields).as_str()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This as_str seems superfluous now (same below).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right - thanks!

@fnune
fnune force-pushed the improve-error-messages branch from e81b892 to 4523ede Compare April 4, 2019 19:34
@tomhoule

Copy link
Copy Markdown
Member

Looks good! We discussed the iter formatting issue on another channel - we should address that concern, rebase and then let's merge this.

@fnune

fnune commented Apr 20, 2019

Copy link
Copy Markdown
Author

So I should rebase and then do the thing without itertools?

@tomhoule

Copy link
Copy Markdown
Member

yep - for the itertools part, you can implement a Display helper, something like:

struct CommaSeparated<T>(T);

impl<A, B> std::fmt::Display for CommaSeparated<A>
where A: Iter<Item=B>,
  B: Display {
 ....
}

@tomhoule

Copy link
Copy Markdown
Member

If it's too hard we can think about keeping the itertools dependency.

@tomhoule

Copy link
Copy Markdown
Member

@fnune the codebase has changed quite a bit since this PR was opened :)

@tomhoule tomhoule closed this Jun 28, 2021
@mathstuf

mathstuf commented Feb 2, 2025

Copy link
Copy Markdown
Contributor

Is this something we should revisit? Improving error messages is almost always a good thing IMO.

@tomhoule

tomhoule commented Feb 3, 2025

Copy link
Copy Markdown
Member

Is this something we should revisit? Improving error messages is almost always a good thing IMO.

yeah definitely. We could have an issue so we don't forget

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants